unit SmallStruct.BusinessObject.TSSAdvancedBusinessObject;

interface

uses SmallStruct.Database,
  SmallStruct.BusinessObject,
  SmallStruct.BusinessObject.TSSBusinessObject;

type
  TSSAdvancedBusinessObjectContext = class(TSSBusinessObjectContext, ISSAdvancedBusinessObjectContext)
  private
    _Database: ISSDatabaseDriver;
  public
    procedure SetDatabase(ADatabase: ISSDatabaseDriver);
  public
    function GetDatabase: ISSDatabaseDriver;
  public
    destructor Destroy; override;
  end;

  TSSAdvancedBusinessObject = class(TSSBusinessObject, ISSAdvancedBusinessObject)
  public
    function GetDatabase: ISSDatabaseDriver;
    function Query(const SQL: string): ISSDataSet;
    procedure ExecuteSQL(const SQL: string);
  end;

  TSSAdvancedBusinessObjectClass = class of TSSAdvancedBusinessObject;

implementation

uses
  Dialogs,
  SmallStruct.Database.TSSADODatabaseDriver;

{ TSSAdvancedBusinessObjectContext }

destructor TSSAdvancedBusinessObjectContext.Destroy;
begin
  inherited;
end;

function TSSAdvancedBusinessObjectContext.GetDatabase: ISSDatabaseDriver;
begin
  Result := _Database;
end;

procedure TSSAdvancedBusinessObjectContext.SetDatabase(ADatabase: ISSDatabaseDriver);
begin
  _Database := ADatabase;
end;

{ TSSAdvancedBusinessObject }

procedure TSSAdvancedBusinessObject.ExecuteSQL(const SQL: string);
begin
  GetDatabase.ExecuteSQL(SQL);
end;

function TSSAdvancedBusinessObject.GetDatabase: ISSDatabaseDriver;
begin
  Result := (GetContext as ISSAdvancedBusinessObjectContext).GetDatabase;
end;

function TSSAdvancedBusinessObject.Query(const SQL: string): ISSDataSet;
begin
  Result := (GetContext as ISSAdvancedBusinessObjectContext).GetDatabase.Query(SQL);
end;

end.
